#include <bits/stdc++.h>
using namespace std;

int t, n;

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    cin>>t;
    while(t--){
        cin>>n;
        int x;
        int ans=0;
        map<int,int> mp;
        for(int i=0; i<n; i++){
            cin>>x;
            mp[x]++;
        }
        map<int,int>::iterator it=mp.begin();
        for(;it!=mp.end(); it++)
            if(it->second>=2) ans+=(it->second-1)*it->first;
        cout<<ans<<endl;
    }

    return 0;
}
